const my = require('../../service/my/my');
const user = require('../../service/user/user');
const sns = require('../../service/sns/sns');
const htag = require('../../utils/html-tag')
const task = require('../../service/task/task');

//获取应用实例
const app = getApp()
const utils = require('../../utils/utils');

Page({
  data: {
    list: [],
    userInfo: {},
    isInit: false
  },

  onLoad: function () {
    let _this = this

    wx.getSystemInfo({
      success: function (res) {
        // console.log('screenWidth:' + res.screenWidth);
        let per = res.screenWidth / 375;
        _this.setData({
          per: per,
          screenWidth: res.screenWidth,
          windowHeight: res.windowHeight
        })
      }
    });
  },

  onShow () {
    if (app.globalData.jwt && app.globalData.userInfo) {
      // console.log(app.globalData)
      this.init();
    }
    // 在此处定义一个全局方法，app.js中获取用户信息成功后，会主动调用该方法
    app.userInfoReadyCallback = () => {
      console.log('调用了user info ready cb')
      this.init()
    }
  },

  init: function () {
    this.setData({
      userInfo: app.globalData.userInfo
    })

    task.list().then(({ data }) => {
      if (data.code === 1000) {
        this.setData({
          list: data.data
        })
      } else {
        console.log(data.msg);
      }
    })
    // this.overTime();
    // this.getBaseInfo();
    // this.getArticleList(true, 0);
    // this.getWeChatCode();
  },
  // 下拉刷新
  onPullDownRefresh: function () {
    this.init();
  },
})